﻿// JavaScript Document
function IMGS(id, w, h, da, c, aid) {
    this.w = w;
    this.h = h;
    this.da = da;
    this.l = da.length;
    this.html = "";
    this.id = id;
    this.child = { img: [], div: [] };
    this.cr = 0;
    this.xx = 0;
    this.m = 10;
    this.pr = null;
    this.time = false;
    this.step = c;
    this.aid = aid;
    this.init();
}
IMGS.prototype = {
    init: function () {
        document.writeln('<div id="' + this.id + '" style="position:fixed;left:0px;right:0px;bottom:0px;z-index:9999;margin:0px auto;cursor:pointer;"></div>');

        this.$(this.id).onclick = function () { addClickCount() };  //添加点击计数方法

        this.SetWidth();
        var self = this;
        for (var i = this.l - 1; i >= 0; i--) {
            var img = document.createElement("img");
            img.width = this.w;
            img.height = this.h;
            img.border = "0";
            img.src = this.da[i].src;
            img.alt = this.da[i].name;
            if (typeof this.da[i].link != "") {
                var a = document.createElement("a");

                if (this.da[i].link.indexOf('http://') >= 0) a.href = this.da[i].link;
                else a.href = 'http://' + this.da[i].link;

                a.appendChild(img);
                this.child.img[i] = a;
                this.$(this.id).appendChild(a);
            } else {
                this.child.img[i] = img;
                this.$(this.id).appendChild(img);
            }
            this.child.img[i].style.cssText += ";position:absolute;left:0px;top:0px;z-index:1;display:none;width:100%;height:100%;";
            if (this.l > 0) this.pr = this.child.img[0];
        }
        window.onresize = function () {
            imgs.SetWidth();
        };
        this.Go();
    },
    Go: function () {
        var self = this;
        for (var i = 0; i < this.l; i++) {
            this.child.img[i].style.zIndex = "1";
        }
        if (this.pr != null) this.pr.style.zIndex = "10";
        this.pr = this.child.img[this.cr];
        this.m = 10;
        with (this.child.img[this.cr].style) { filter = 'alpha(opacity=10)'; opacity = 0.1; display = ""; zIndex = "20"; }
        this.None(self, this.child.img[this.cr]);
        if (++this.cr == this.l) this.cr = 0;
        if (this.l > 1) this.time = setTimeout(function () { self.Go() }, this.step);
    },
    None: function (self, tt) {
        var none = setInterval(function () {
            with (tt.style) { filter = 'alpha(opacity=' + self.m + ')'; opacity = (self.m / 100); }
            self.m += 5;
            if (self.m > 101) window.clearInterval(none);
        }, 10);
    },
    Close: function () {
        this.$(this.id).hidden = 'hidden';
    },
    SetWidth: function () {
        var width = document.body.clientWidth - document.body.scrollLeft;
        if (width < 640) {
            this.h = (width / this.w) * this.h;
            this.w = width;
            //this.w = 640;
            //this.h = 100;
        }
        else {
            this.w = 640;
            this.h = 119;
        }
        with (this.$(this.id).style) { width = this.w + 'px'; height = this.h + 'px' }
        var close = null;
        if (document.getElementById('MonkeyFly_PicPlayer_closer')) {
            close = document.getElementById('MonkeyFly_PicPlayer_closer');
        }
        else {
            close = document.createElement("div");
            close.className = "MonkeyFly_PicPlayer_close";
            close.id = 'MonkeyFly_PicPlayer_closer';
        }
        var style = document.createElement("style");
        document.head.appendChild(style);
        style.sheet.insertRule('.MonkeyFly_PicPlayer_close{display: block;position: relative;float: right;z-index: 10000;width:' + (this.h / 4) + 'px;height:' + (this.h) + 'px;right:0;top:' + (this.h / 8) * 3 + 'px;}', 0);
        style.sheet.insertRule('.MonkeyFly_PicPlayer_close::before, .MonkeyFly_PicPlayer_close::after{height:' + (this.h / 4) + 'px;width:' + (this.h / 30) + 'px;top:0;content: "";display: block;background: #A9A9A9;position: absolute;left: 1px;transform: rotate(-45deg);-webkit-transform: rotate(-45deg);-moz-transform: rotate(-45deg);-o-transform: rotate(-45deg);-ms-transform: rotate(-45deg);}', 1);
        style.sheet.insertRule('.MonkeyFly_PicPlayer_close::after{transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);-o-transform: rotate(45deg);-ms-transform: rotate(45deg);}', 2);

        close.onclick = function () { imgs.Close(); };
        var theimgs = this.$(this.id).getElementsByTagName('img');
        if (theimgs) {
            for (var i in theimgs) {
                theimgs[i].width = this.w;
                theimgs[i].height = this.h;
            }
        }

        this.$(this.id).appendChild(close);
    },
    $: function (id) { return document.getElementById(id); }
}

function checkSystem() {
    //平台、设备和操作系统
    var system = {
        win: false,
        mac: false,
        xll: false
    };
    //检测平台
    var p = navigator.platform;
    system.win = p.indexOf("Win") == 0;
    system.mac = p.indexOf("Mac") == 0;
    system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
    //如果是pc返回true，否则视为手持客户端返回false
    return (system.win || system.mac || system.xll);
}

function addClickCount(link) {
    if (imgs.aid) {
        $.ajax({
            url: '/zf/click',
            method: 'post',
            data: { code: imgs.aid },
            success: function (data) { }
        });
    }
}